package com.easychat;

import com.easychat.redis.RedisUtils;
import io.lettuce.core.RedisConnectionException;
import org.apache.ibatis.session.SqlSessionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * @author kyle.li
 * @version 1.0
 * @description: TODO
 * @date 2024/7/4 22:03
 */
@Component
public class InitRun implements ApplicationRunner {
    private static final Logger logger = LoggerFactory.getLogger(InitRun.class);

    @Resource
    private DataSource dataSource;

    @Resource
    private RedisUtils redisUtils;

    @Override
    public void run(ApplicationArguments args){
        try{
            dataSource.getConnection();
            redisUtils.get("test");
            logger.info("服务启动成功，祝你好运！！！");
        }catch (SqlSessionException e){
            logger.error("mysql连接失败，请检查数据库配置");
        }catch (RedisConnectionException e){
            logger.error("redis连接失败，请检查redis配置");
        }catch (Exception e){
            logger.error("服务启动失败,上帝保佑~~~",e);
        }
    }
}
